﻿using ERP_RORZE_DLL.Product.Base;
using ERP_RORZE_DLL.Product.database;
using System;using ERP_RORZE_SYSTEM;
using System.Collections.Generic;
using System.Data;using ERP_RORZE_SYSTEM;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ERP_RORZE_DLL.Product.DAO
{
    public class ClsMonthlyExpenceDAO : ExecuteSQL
    {
        ExecuteSQL Execute = new ExecuteSQL();
        public DataTable GetAllMonthlyExpence()
        {
            string sql = clsConstantsFuction.ClsFuctionExpence.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }
        public void InsertMonthlyExpence(MonthlyExpence b)
        {

            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMonthlyExpenceSP.ExpenceID, SqlDbType.NVarChar, b.ExpenceID),
                    CreateParameter(clsConstantsSP.ClsMonthlyExpenceSP.YearMonth, SqlDbType.DateTime, b.YearMonth),
                    CreateParameter(clsConstantsSP.ClsMonthlyExpenceSP.Amount, SqlDbType.Money, b.Amount)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionMonthlyExpence.Insert, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void UpdateMonthlyExpence(MonthlyExpence b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMonthlyExpenceSP.ID, SqlDbType.Int, b.ID),
                    CreateParameter(clsConstantsSP.ClsMonthlyExpenceSP.ExpenceID, SqlDbType.NVarChar, b.ExpenceID),
                    CreateParameter(clsConstantsSP.ClsMonthlyExpenceSP.YearMonth, SqlDbType.DateTime, b.YearMonth),
                    CreateParameter(clsConstantsSP.ClsMonthlyExpenceSP.Amount, SqlDbType.Money, b.Amount)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionMonthlyExpence.Update, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void DeleteMonthlyExpence(MonthlyExpence b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMonthlyExpenceSP.ID, SqlDbType.Int, b.ID)
                };
                Execute.DoDelete(clsConstantsFuction.ClsFuctionMonthlyExpence.Delete, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public DataTable GetAllMonthlyLaborByDate(MonthlyLaborCharge b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMonthlyLaborChargeSP.LYear, SqlDbType.Int, b.Year),
                    CreateParameter(clsConstantsSP.ClsMonthlyLaborChargeSP.LMonth, SqlDbType.Int, b.Month)
                    
                };
            return Execute.DoStoreGetByID(clsConstantsFuction.ClsFuctionMO.GetAllByDate, parameter, true);
        }

        public DataTable GetAllMonthlyMachineByDate(MonthlyMachineCharge b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMonthlyMachineChargeSP.MYear, SqlDbType.Int, b.Year),
                    CreateParameter(clsConstantsSP.ClsMonthlyMachineChargeSP.MMonth, SqlDbType.Int, b.Month)
                    
                };
            return Execute.DoStoreGetByID(clsConstantsFuction.ClsFuctionMO.GetAllMachineByDate, parameter, true);
        }

        public void InsertLaborChargeUpdate(MonthlyLaborCharge b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMonthlyLaborChargeSP.LYear, SqlDbType.Int, b.Year),
                    CreateParameter(clsConstantsSP.ClsMonthlyLaborChargeSP.LMonth, SqlDbType.Int, b.Month)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionMonthlyLaborCharge.Insert, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void InsertMachineChargeUpdate(MonthlyMachineCharge b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMonthlyMachineChargeSP.MYear, SqlDbType.Int, b.Year),
                    CreateParameter(clsConstantsSP.ClsMonthlyMachineChargeSP.MMonth, SqlDbType.Int, b.Month)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionMonthlyMachineCharge.Insert, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
    }
}
